//
//  BBTaskDetailViewController.m
//  BearSiX
//
//  Created by BearBaby on 16/3/28.
//  Copyright © 2016年 Tom. All rights reserved.
//

#import "BBTaskDetailViewController.h"
#import "BBSixHeader.h"
#import "BBTaskDetailCell.h"
#import "ASValueTrackingSlider.h"
@interface BBTaskDetailViewController ()<UITableViewDelegate,UITableViewDataSource>
@property(nonatomic,strong)UITableView* tableView;
@property(nonatomic,strong)NSArray* images;
@property(nonatomic,strong)NSArray* names;
@property(nonatomic,strong)ASValueTrackingSlider *slider1;
@property(nonatomic,strong)UIView* view1;        //底部按钮
@end

@implementation BBTaskDetailViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    self.title = @"任务详情";
    self.images = @[@"2.png",@"2.png",@"2.png",@"2.png"];
    self.names = @[@"LiMei",@"萌萌",@"小咩",@"林琳"];
    self.view.backgroundColor = [UIColor whiteColor];
    self.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc]initWithTitle:@"编辑" style:UIBarButtonItemStyleDone target:self action:@selector(edit)];
    self.tableView = [[UITableView alloc]initWithFrame:CGRectMake(0, 0, WINSIZEWIDTH, WINSIZEHEIGHT) style:UITableViewStyleGrouped];
    self.tableView.delegate = self;
    self.tableView.dataSource = self;
    [self.view addSubview:self.tableView];
     [self addFooterButton];
}


/**
 *  添加底部按钮
 */
-(void)addFooterButton
{
    self.view1 = [[UIView alloc]initWithFrame:CGRectMake(0, 100, 20, 44)];
    self.view1.backgroundColor = [UIColor clearColor];
    self.tableView.tableFooterView = self.view1;
    
    
    //1.初始化Button
    UIButton *button = [UIButton buttonWithType:UIButtonTypeRoundedRect];
    
    //2.设置文字和文字颜色
    [button setTitle:@"完成" forState:UIControlStateNormal];
    [button setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
    
    //3.设置圆角幅度
    button.layer.cornerRadius = 5.0;
    
    //4.设置frame
    button.frame = CGRectMake(WINSIZEWIDTH/3, 0, WINSIZEWIDTH/3, 44);
    
    //5.设置背景色
    button.backgroundColor = [UIColor colorWithHexString:@"d6d6d6"];
    
    //6.设置触发事件
    [button addTarget:self action:@selector(done:) forControlEvents:UIControlEventTouchUpInside];
    //省略
    [self.view1 addSubview:button];
}
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
    return 4;
}


- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{

    return 1;
}



- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    static NSString* identifire = @"Cell";
    BBTaskDetailCell* cell = [self.tableView dequeueReusableCellWithIdentifier:identifire];
    if (indexPath.section==0) {
        
        if (!cell) {
            cell = [[BBTaskDetailCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:identifire];
        }
    }else if(indexPath.section==1){
        UITableViewCell* cell1 = [[UITableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:nil];
        //任务进度
        UILabel* speedLabel = [[UILabel alloc]init];
        speedLabel.text = @"任务进度";
        speedLabel.font = [UIFont systemFontOfSize:WINSIZEWIDTH/25];
        CGSize speedSize = [speedLabel.text sizeWithFont:speedLabel.font constrainedToSize:CGSizeMake(300, 300) lineBreakMode:NSLineBreakByCharWrapping];
        speedLabel.frame = CGRectMake(15, 15, speedSize.width, speedSize.height);
        [cell1 addSubview:speedLabel];
        //可编辑
        UILabel* editLabel = [[UILabel alloc]init];
        editLabel.text = @"(可编辑)";
        editLabel.textColor = [UIColor colorWithHexString:@"666666"];
        editLabel.font = [UIFont systemFontOfSize:WINSIZEWIDTH/25];
        CGSize editSize = [editLabel.text sizeWithFont:editLabel.font constrainedToSize:CGSizeMake(300, 300) lineBreakMode:NSLineBreakByCharWrapping];
        editLabel.frame = CGRectMake(WINSIZEWIDTH - 15 - editSize.width, 15, editSize.width, editSize.height);
        [cell1 addSubview:editLabel];
        //左右轨的图片
        UIImage *stetchLeftTrack= [UIImage imageNamed:@"14-5"];
        UIImage *stetchRightTrack = [UIImage imageNamed:@"14-6"];
        //滑块图片
        UIImage *thumbImage = [UIImage imageNamed:@""];
        self.slider1 = [[ASValueTrackingSlider alloc]initWithFrame:CGRectMake(20, 80, self.view.frame.size.width - 40, 20)];
        [self.slider1 setMinimumTrackImage:stetchLeftTrack forState:UIControlStateNormal];
        [self.slider1 setMaximumTrackImage:stetchRightTrack forState:UIControlStateNormal];
        //注意这里要加UIControlStateHightlighted的状态，否则当拖动滑块时滑块将变成原生的控件
        [self.slider1 setThumbImage:thumbImage forState:UIControlStateHighlighted];
        [self.slider1 setThumbImage:thumbImage forState:UIControlStateNormal];

        self.slider1.maximumValue = 100;
        self.slider1.popUpViewCornerRadius = 0.0;
        [self.slider1 setMaxFractionDigitsDisplayed:0];
        self.slider1.popUpViewColor = [UIColor redColor];
        self.slider1.font = [UIFont systemFontOfSize:WINSIZEWIDTH/25];
        self.slider1.textColor = [UIColor whiteColor];
         [self.slider1 showPopUpView];
        [cell1 addSubview:self.slider1];
        
        return cell1;
    
    
    }else if(indexPath.section==2){
        UITableViewCell* cell2 = [[UITableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:nil];
        //任务进度
        UILabel* memberLabel = [[UILabel alloc]init];
        memberLabel.text = @"任务成员";
        memberLabel.font = [UIFont systemFontOfSize:WINSIZEWIDTH/25];
        CGSize memberSize = [memberLabel.text sizeWithFont:memberLabel.font constrainedToSize:CGSizeMake(300, 300) lineBreakMode:NSLineBreakByCharWrapping];
        memberLabel.frame = CGRectMake(15, 15, memberSize.width, memberSize.height);
        [cell2 addSubview:memberLabel];
        //可编辑
        UILabel* numberLabel = [[UILabel alloc]init];
        numberLabel.text = @"8人";
        numberLabel.font = [UIFont systemFontOfSize:WINSIZEWIDTH/25];
        CGSize numberSize = [numberLabel.text sizeWithFont:numberLabel.font constrainedToSize:CGSizeMake(300, 300) lineBreakMode:NSLineBreakByCharWrapping];
        numberLabel.frame = CGRectMake(WINSIZEWIDTH - 15 - numberSize.width, 15, numberSize.width, numberSize.height);
        [cell2 addSubview:numberLabel];
        //成员头像
        UIImageView* headImage;
        for (int i = 0; i<self.images.count; i++) {
            headImage = [[UIImageView alloc]initWithFrame:CGRectMake(15 + (50+25)*i, CGRectGetMaxY(memberLabel.frame)+10, 50, 50)];
            
            headImage.layer.cornerRadius = 25;
            headImage.layer.masksToBounds = YES;
            headImage.image = [UIImage imageNamed:[NSString stringWithFormat:@"%@",self.images[i]]];
            [cell2 addSubview:headImage];
        }
        //成员姓名
        for (int i = 0; i<self.names.count; i++) {
            UILabel* nameLabel = [[UILabel alloc]init];
            nameLabel.text = self.names[i];
            nameLabel.textAlignment = NSTextAlignmentCenter;
            nameLabel.font = [UIFont systemFontOfSize:WINSIZEWIDTH/27];
            CGSize nameSize = [nameLabel.text sizeWithFont:nameLabel.font constrainedToSize:CGSizeMake(300, 300) lineBreakMode:NSLineBreakByWordWrapping];
            nameLabel.frame = CGRectMake(15 + (50+25)*i, CGRectGetMaxY(headImage.frame)+5, 50, nameSize.height);
            [cell2 addSubview:nameLabel];
            
            
        }
        cell2.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
        return cell2;
        
        
    }else if(indexPath.section==3){
        UITableViewCell* cell3 = [[UITableViewCell alloc]initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:nil];
        
        cell3.textLabel.text = @"截止时间";
        cell3.detailTextLabel.text = @"2015年12月30日";
        cell3.textLabel.font = [UIFont systemFontOfSize:WINSIZEWIDTH/25];
        cell3.detailTextLabel.font = [UIFont systemFontOfSize:WINSIZEWIDTH/25];
        return cell3;
        
        
    }

    return cell;
}
-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
    if (indexPath.section==0) {
        CGFloat cellHeight = 0.0f;
        BBTaskDetailCell* cell = (BBTaskDetailCell*)[self tableView:(UITableView*)tableView cellForRowAtIndexPath:(NSIndexPath*)indexPath];
        cellHeight = cell.finalH;
        
        return cellHeight;
    }else if(indexPath.section==1){
        return 120;
    
    }else if (indexPath.section==2){
        return 130;
    
    }
        return 44;
   
}
-(CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section{
 
    return 15;
}
-(CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section{

    return 0.0000001;
}
//编辑
-(void)edit{



}
@end
